
import java.sql.Connection;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

//import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**

 */
public class Conexion {



    public String modificar(String clave, String producto, String descripcion, String categoria, String umedida, String precio, String stock) {
        try {

            Class.forName("org.gjt.mm.mysql.Driver");

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            Connection c = DriverManager.getConnection("jdbc:mysql://localhost/puntoventa", "root", "");
            PreparedStatement stm = c.prepareStatement("update productos set producto=?,descripcion=?,categoria=?,umedida=?,precio=?,stock=? where clave=?");
//Statement stl=c.createStatement();
           
             stm.setString(1, producto);
            stm.setString(2, descripcion);
            stm.setString(3, categoria);
            stm.setString(4, umedida);
            stm.setString(5, precio);
            stm.setString(6, stock);
            stm.setString(7, clave);
             
             stm.executeUpdate();



       
        } catch (SQLException ex) {
            Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
        }


        return producto;

    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

     public String insertar(String clave, String producto, String descripcion, String categoria, String umedida, String precio, String stock) {
        try {

            Class.forName("org.gjt.mm.mysql.Driver");

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            Connection c = DriverManager.getConnection("jdbc:mysql://localhost/puntoventa", "root", "");
            PreparedStatement stm = c.prepareStatement("insert into productos values (?,?,?,?,?,?,?)");

           
            stm.setString(1, clave);
            stm.setString(2, producto);
            stm.setString(3, descripcion);
            stm.setString(4, categoria);
            stm.setString(5, umedida);
            stm.setString(6, precio);
            stm.setString(7, stock);
             
             
             stm.executeUpdate();



        //stm.execute("insert into usuarios values ('12345','alex','josefa','3333333333')");
        } catch (SQLException ex) {
            Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
        }


        return producto;

    }
     //////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
         public String eliminar(String clave) {
        try {

            Class.forName("org.gjt.mm.mysql.Driver");

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            Connection c = DriverManager.getConnection("jdbc:mysql://localhost/puntoventa", "root", "");
            PreparedStatement stm = c.prepareStatement("delete from productos where clave=?");

           
            stm.setString(1, clave);
           
             
             
             stm.executeUpdate();



        //stm.execute("insert into usuarios values ('12345','alex','josefa','3333333333')");
        } catch (SQLException ex) {
            Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
        }


        return clave;

    }
         public String insertarv(String producto, String descripcion, String umedida, String precio) {
        try {

            Class.forName("org.gjt.mm.mysql.Driver");

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            Connection c = DriverManager.getConnection("jdbc:mysql://localhost/puntoventa", "root", "");
            PreparedStatement stm = c.prepareStatement("insert into venta values (?,?,?,?)");



            stm.setString(1, producto);
            stm.setString(2, descripcion);

            stm.setString(3, umedida);
            stm.setString(4, precio);



             stm.executeUpdate();




        } catch (SQLException ex) {
            Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
        }


        return producto;

    }
    
}
